using UnityEngine;

public class PvPLeaderbord : MonoBehaviour
{
	public static PvPLeaderbord instance;

	public ListPlayersPVP playersScroll_1;

	public ListPlayersPVP playersScroll_2;

	public UIButton btn;

	public GameObject BigButton;

	private void Awake()
	{
		instance = this;
		BigButton.SetActive(false);
		if (TDMController.isTeamGameType)
		{
			playersScroll_1.active = true;
			playersScroll_1.transform.localPosition = new Vector3(-220f, playersScroll_1.transform.localPosition.y, 0f);
			playersScroll_2.active = true;
			playersScroll_2.transform.localPosition = new Vector3(220f, playersScroll_2.transform.localPosition.y, 0f);
			if (TDMController.myTeam != 0)
			{
				playersScroll_1.Init(true);
			}
			if (TDMController.enemyTeam != 0)
			{
				playersScroll_2.Init(false);
			}
		}
		else
		{
			playersScroll_1.active = true;
			playersScroll_1.Init(true);
			playersScroll_1.transform.localPosition = new Vector3(0f, playersScroll_1.transform.localPosition.y, 0f);
			playersScroll_2.active = false;
		}
		if (GameController.instance.curTypeGame == TypeGame.race)
		{
			btn.gameObject.SetActive(false);
		}
		playersScroll_1.Show(false);
		playersScroll_2.Show(false);
		playersScroll_1.parentSV.disableDragIfFits = true;
		playersScroll_2.parentSV.disableDragIfFits = true;
		base.enabled = false;
		MapEntrance.OnEnterMapTrigger += delegate
		{
			instance.EnableLeaderboard(false);
		};
		MapEntrance.OnExitMapTrigger += delegate
		{
			instance.EnableLeaderboard(true);
		};
	}

	private void OnEnable()
	{
		Refrash();
	}

	public void Refrash()
	{
		if (TDMController.myTeam != 0)
		{
			playersScroll_1.Init(true);
		}
		if (TDMController.enemyTeam != 0)
		{
			playersScroll_2.Init(false);
		}
		PlayerBehavior.MyPlayer.UpdateMyPlayerPlace();
		if (GameController.instance.curTypeGame != TypeGame.race)
		{
			btn.gameObject.SetActive(!settings.offlineMode);
			if ((TDMController.isTeamGameType && GameController.instance.curTypeGame != TypeGame.CopsAndRobbers) || GameController.instance.curTypeGame == TypeGame.TitanfallV2)
			{
				btn.GetComponent<UISprite>().enabled = false;
				btn.enabled = false;
			}
		}
		if (settings.offlineMode)
		{
			return;
		}
		if ((bool)GameTopWindow.instance)
		{
			if ((bool)GameController.instance && GameController.instance.listPlayers.Count < 2 && (GameController.instance.curTypeGame != TypeGame.race || !RaceController.instance.enableMove))
			{
				GameTopWindow.instance.messageWait.SetActive(true);
			}
			else
			{
				TypeGame curTypeGame = GameController.instance.curTypeGame;
				if ((curTypeGame == TypeGame.tanks || curTypeGame == TypeGame.TDM || curTypeGame == TypeGame.Zombe) && !PVPManager.instance.gameIsStarted && GameController.instance.listPlayers.Count == 1)
				{
					GameTopWindow.instance.messageWait.SetActive(true);
				}
				else
				{
					GameTopWindow.instance.messageWait.SetActive(false);
				}
			}
		}
		playersScroll_1.CreatePlayer();
		playersScroll_2.CreatePlayer();
	}

	public void OnClick()
	{
		SwitchListPlayers();
	}

	public void SwitchListPlayers(bool? active = null)
	{
		if (!active.HasValue)
		{
			base.enabled = !base.enabled;
		}
		else
		{
			base.enabled = active.Value;
		}
		playersScroll_1.Show(base.enabled);
		playersScroll_2.Show(base.enabled);
		BigButton.SetActive(base.enabled);
	}

	public void EnableLeaderboard(bool canShow)
	{
		if (!settings.offlineMode)
		{
			playersScroll_1.Show(false);
			playersScroll_2.Show(false);
			BigButton.transform.parent.gameObject.SetActive(canShow);
		}
	}

	private void OnDestroy()
	{
		MapEntrance.OnEnterMapTrigger -= delegate
		{
			EnableLeaderboard(false);
		};
		MapEntrance.OnExitMapTrigger -= delegate
		{
			EnableLeaderboard(true);
		};
	}
}
